/**
 * The Hand class is a subclass of the CardList class and is used to model a hand of cards. It has
 * a private instance variable for storing the player who plays this hand. It also has methods for
 * getting the player of this hand, checking if it is a valid hand, getting the type of this hand,
 * getting the top card of this hand, and checking if it beats a specified hand.
 *
 * @author Jiang Feiyu
 *
 */
public class Hand extends CardList{
    /**
     * Player who plays the hand.
     */
    private CardGamePlayer player;
    /**
     * Constructor for Hand class that gives value to player and cards(instance variable of the CardList).
     *
     * @param player Player who played the hand.
     * @param cards list of card that the player played.
     */
    public Hand(CardGamePlayer player, CardList cards) {
        this.player = new CardGamePlayer();
        this.player = player;
        int i = 0;
        while (i < cards.size()){
            this.addCard(cards.getCard(i));
            i = i + 1;
        }
    }
    /**
     * Getter function for player who played this hand.
     *
     * @return player of the current hand object.
     */
    public CardGamePlayer getPlayer() {
        return this.player;
    }
    /**
     * This method returns the top card of the hand.
     *
     * @return returns the top card of the particular hand formed.
     */
    public Card getTopCard() {
        return null;
    }
    /**
     * Returns true if the hand is a of a valid type and false otherwise
     *
     * @return true if hand is valid, false otherwise
     */
    public boolean isValid() {
        return true;
    }
    /**
     * Returns the name of the type of hand
     *
     * @returnR the name of the type of hand in string
     */
    public String getType() {
        return "";
    }
    /**
     * This method compares two hands and checks whether this hand beats the hand send through the argument.
     *
     * @param hand The hand that needs to be compared with this hand.
     * @return true if this hand beats the hand send as an argument, false otherwise.
     */
    public boolean beats(Hand hand) {
        if (hand == null){
            return false;
        }
        if(hand.size() == 1 && this.size() == 1){
            if (this.isValid() && hand.isValid() && (this.getTopCard().compareTo(hand.getTopCard()) == 1)){
                return true;
            }
        }
        else if(hand.size() == 2 && this.size() ==2) {
            if((this.isValid() && hand.isValid()) && (this.getTopCard().compareTo(hand.getTopCard()) == 1)) {
                return true;
            }
        }
        else if(hand.size() ==3 && this.size() ==3) {
            if((this.isValid() && hand.isValid()) && (this.getTopCard().compareTo(hand.getTopCard()) == 1)) {
                return true;
            }
        }
        else if(hand.size() == 5 && this.size()==5) {
            // compare with same type
            if(this.getType() == hand.getType()) {
                return this.getTopCard().compareTo(hand.getTopCard())==1;
            }
            // compare with different type
            else {
                if(this.getType()== "StraightFlush") {
                    return true;
                }
                else if(this.getType()== "Quad") {
                    switch (hand.getType()){
                        case "StraightFlush":
                            return false;
                        default:
                            return true;
                    }
                }
                else if(this.getType() == "FullHouse") {
                    switch (hand.getType()){
                        case "StraightFlush":
                        case "Quad":
                            return false;
                        default:
                            return true;
                    }
                }
                else if(this.getType() == "Flush") {
                    switch (hand.getType()){
                        case "StraightFlush":
                        case "Quad":
                        case "FullHouse":
                            return false;
                        default:
                            return true;
                    }
                }
                else if(this.getType() == "Straight") {
                    return false;
                }
            }
        }
        return false;
    }
    }